import Vue from "vue";
import axios from "axios";
import VueAxios from "vue-axios";
import tokenUtil from "@/core/util/tokenUtil.js";
import Swal from "sweetalert2";
import Router from "@/router.js";
import {handleNotify,handleAlert,showWating,closeWating} from "@/core/util/jehcUtil.js";
import request from "@/core/util/request.js"

/**
 * Service to call HTTP request via Axios
 */
const apiUtil = {
  init() {
    
  },
  
  /**
   * Set the default HTTP request headers
   */
  setHeader() {
   
  },

  /**
   * 分页查询（post方式查询）
   * @param {*} resource 
   * @param {*} params 
   * @returns 
   */
  queryPage(resource, params) {
    // this.setHeader();//设置请求前增加header
    return request({
      url:resource,
      method:'post',
      data:params
    })
  },

  /**
   * get方式查询
   * @param {*} resource 
   * @param {*} params 
   * @returns 
   */
  query(resource, params) {
    // this.setHeader();//设置请求前增加header
    // return axios.get(`${resource}`, {params:params}).catch(error => {
    //   // console.log(error);
    //   // throw new Error(`[KT] apiUtil ${error}`);
    // });
    return request({
      url:`${resource}`,
      method:'get',
      params:params
    })
  },

  /**
   * Send the GET HTTP request
   * @param resource
   * @param slug
   * @returns {*}
   */
  get(resource, slug = "") {
    // this.setHeader();//设置请求前增加header
    // return axios.get(`${resource}/${slug}`).catch(error => {
    //   // console.log(error);
    //   // throw new Error(`[KT] apiUtil ${error}`);
    // });
    
    return request({
      url:`${resource}/${slug}`,
      method:'get',
    })
  },


  /**
   * Send the GET HTTP request
   * @param resource
   * @param slug
   * @returns {*}
   */
  get(resource, params) {
    // this.setHeader();//设置请求前增加header
    // return axios.get(`${resource}`, {params:params}).catch(error => {
    //   // console.log(error);
    //   // throw new Error(`[KT] apiUtil ${error}`);
    // });
    
    return request({
      url:`${resource}`,
      method:'get',
      params:params
    })
  },

  // /**
  //  * Send the GET HTTP request
  //  * @param resource
  //  * @param params
  //  * @returns {*}
  //  */
  // get(resource, params) {
  //   // this.setHeader();//设置请求前增加header
  //   return axios.get(resource, params).catch(error => {
  //     // console.log(error);
  //     throw new Error(`[KT] apiUtil ${error}`);
  //   });
  // },

  /**
   * Set the POST HTTP request
   * @param resource
   * @param params
   * @returns {*}
   */
  post(resource, params) {
    // this.setHeader();//设置请求前增加header
    // return axios.post(`${resource}`, params).catch(error => {
    //   // console.log(error);
    //   // throw new Error(`[KT] apiUtil ${error}`);
    // });
    return request({
      url:`${resource}`,
      method:'post',
      data:params
    })
  },

  /**
   * Send the UPDATE HTTP request
   * @param resource
   * @param slug
   * @param params
   * @returns {IDBRequest<IDBValidKey> | Promise<void>}
   */
  update(resource, slug, params) {
    // this.setHeader();//设置请求前增加header
    // return axios.put(`${resource}/${slug}`, params).catch(error => {
    //   // console.log(error);
    //   // throw new Error(`[KT] apiUtil ${error}`);
    // });

    return request({
      url:`${resource}/${slug}`,
      method:'put',
      data:params
    })

  },

  /**
   * Send the UPDATE HTTP request
   * @param resource
   * @param params
   * @returns {IDBRequest<IDBValidKey> | Promise<void>}
   */
  update(resource, params) {
    // this.setHeader();//设置请求前增加header
    // return axios.put(`${resource}`, params).catch(error => {
    //   // console.log(error);
    //   // throw new Error(`[KT] apiUtil ${error}`);
    // });
    return request({
      url:`${resource}`,
      method:'put',
      data:params
    })
  },

  /**
   * Send the PUT HTTP request
   * @param resource
   * @param params
   * @returns {IDBRequest<IDBValidKey> | Promise<void>}
   */
  put(resource, params) {
    // this.setHeader();//设置请求前增加header
    // return axios.put(`${resource}`, params).catch(error => {
    //   // console.log(error);
    //   // throw new Error(`[KT] apiUtil ${error}`);
    // });
    
    return request({
      url:`${resource}`,
      method:'put',
      data:params
    })
  },

  /**
   * Send the DELETE HTTP request
   * @param resource
   * @returns {*}
   */
  delete(resource) {
    // this.setHeader();//设置请求前增加header
    // return axios.delete(resource).catch(error => {
    //   // console.log(error);
    //   // throw new Error(`[RWV] apiUtil ${error}`);
    // });    
    
    return request({
      url:`${resource}`,
      method:'delete',
    })
  },

  /**
   * Send the DELETE HTTP request
   * @param resource
   * @returns {*}
   */
  delete(resource,params) {
    // this.setHeader();//设置请求前增加header
    // return axios.delete(`${resource}`, {params:params}).catch(error => {
    //   // console.log(error);
    //   // throw new Error(`[RWV] apiUtil ${error}`);
    // });
    
    return request({
      url:`${resource}`,
      method:'delete',
      params:params
    })
  },

  /**
   * Send the DELETE HTTP request
   * @param resource
   * @returns {*}
   */
  deleteByDataParams(resource,params) {
    // this.setHeader();//设置请求前增加header
    // return axios.delete(`${resource}`, {params:params}).catch(error => {
    //   // console.log(error);
    //   // throw new Error(`[RWV] apiUtil ${error}`);
    // });
    
    return request({
      url:`${resource}`,
      method:'delete',
      data:params
    })
  }
};
export default apiUtil;
